import Vue from 'vue'
import Vuex from 'vuex'

//挂载Vuex
Vue.use(Vuex)

//创建VueX对象
const store = new Vuex.Store({
	state: {
		//存放的键值对就是所要管理的状态
		comment: '',
		user: [],
		currentUsername: '',
		goodList: [], //用来保存所有商品信息
		moneyList: [],
	},
	mutations: {
		getlist(state, list) {
			state.comment = list;
		},
		getUserName(state, datas) {
			state.currentUsername = datas;
		},
		getUser(state, datas) {
			// this.state.user=[];
			var jsonLength = 0;
			for (var item in datas.data) {
				jsonLength++;
			}
			for (let i = 0; i < jsonLength; i++) {
				let sex;
				if (datas.data[i].sex == "1") {
					sex = "男";
				}
				else {
					sex = "女";
				}
				let role;
				if (datas.data[i].role == "1") {
					role = "买家";
				}
				else {
					role = "卖家";
				}


				state.user.push({
					id: datas.data[i].id,
					name: datas.data[i].name,
					sex: sex,
					role: role,
					email: datas.data[i].email
				})
			}
		},
		getGoodList(state, datas) {
			var jsonLength = 0;
			for (var item in datas.data) {
				jsonLength++;
			}
			for (let i = 0; i < jsonLength; i++) {
				state.goodList.push({
					id: datas.data[i].id,
					name: datas.data[i].name,
					price: datas.data[i].price,
					desc: datas.data[i].desc,
					photo: datas.data[i].photo
				})
			}
		},
		getMoneyList(state, datas) {
			var jsonLength = 0;
			for (var item in datas.data) {
				jsonLength++;
			}
			for (let i = 0; i < jsonLength; i++) {
				state.moneyList.push({
					id: datas.data[i].id,
					name: datas.data[i].name,
					price: datas.data[i].price,
					number: datas.data[i].number,
					total: datas.data[i].total
				})
			}
		}
	},
	actions: {

	}

})

export default store